package com.tommy.ddp.disposeHandler.special
{
	import com.tommy.ddp.GridDataManager;
	import com.tommy.ddp.MainManager;
	import com.tommy.ddp.box.DdpBox;
	import com.tommy.ddp.definition.BoxExeType;
	import com.tommy.ddp.disposeHandler.IDisposeHandler;
	import com.tommy.ddp.manager.DisposeBoxManager;
	import com.tommy.ddp.swapHandle.SubDisposeVo;
	
	import flash.utils.setTimeout;

	/**
	 * 把某一种颜色全变成X或Y消除功能型棋子。再消除
	 * @author hongxuan
	 * 
	 */	
	public class DisposeAllColorWithXYHandler implements ISpecialDisposeHandler
	{
		private var _color:uint;
		
		private var _vect:Vector.<DdpBox>;
		
		public function DisposeAllColorWithXYHandler()
		{
		}
		
		public function dispose(vect:Vector.<DdpBox>,n:Number):void
		{
			for each(var i:DdpBox in vect)
			{
				if(i.exeType != BoxExeType.SUPER_BOOM)
				{
					_color = i.colorType;
				}
				i.dispose();
				GridDataManager.removeBox(i);
			}
			MainManager.game.tips = "变身，糖果们~~~";
			//
			_vect = new Vector.<DdpBox>();
			var arr:Array = GridDataManager.allBox;
			var exe:Array = [BoxExeType.X_AXIS_ALL,BoxExeType.Y_AXIS_ALL];
			for each(i in arr)
			{
				var r:uint = Math.floor(Math.random()*exe.length);
				if(i.colorType == _color)
				{
					i.setType(i.colorType,exe[r]);
					_vect.push(i);
				}
			}
			setTimeout(_dispose,n);
		}
		
		private function _dispose():void
		{
			var vo:SubDisposeVo = new SubDisposeVo();
			vo.vect = _vect;
			
			DisposeBoxManager.disposeSubVo(vo);
			
			_vect = null;
		}
	}
}